{extend name="public:base" /}
{block name="title"}{$site_title}{/block}
{block name="content"}
<!--/sidebar-->

<div class="main-wrap">
    <div class="crumb-wrap">
        <div class="crumb-list">
            <i class="icon-font"></i>
            <a href="/baibu/admin/Index">首页</a>
            <span class="crumb-step">&gt;</span>
            <a class="crumb-name" href="/baibu/admin/Setting/banner">轮播图</a>
            <span class="crumb-step">&gt;</span>
            <span>{$nav}</span>
        </div>
    </div>
    <div class="result-wrap">
        <div class="result-content">
            <form action="{$url}" method="post" id="myform" name="myform" enctype="multipart/form-data">
                <table class="insert-tab" width="100%">
                    <tbody>
                    <tr>
                        <th width="120">轮播图：
                        </th>
                        <td>
                            <img src="/baibu/public/static/image/default/default.jpg" id="img" style="width: 450px; height: 125px;padding:5px 0 5px 0;">
                            <input class="common-text required" name="banner" hidden type="file">
                        </td>
                    </tr>
                    <tr>
                        <th></th>
                        <td>
                            <input id="sub" class="btn btn-primary btn6 mr10" value="提交" type="button">
                            <input class="btn btn6" onclick="history.go(-1)" value="返回" type="button">
                        </td>
                    </tr>
                    </tbody>
                </table>
            </form>
        </div>
    </div>
</div>
<!--/main-->
{/block}
{block name="js"}
<script>
    $(function () {
        $('#img').click(function () {
            $('input[name=banner]').click();
        });

        $('input[name=banner]').change(function () {
            if(this.files[0]){
                var objUrl = getObjectURL(this.files[0]) ;//获取文件信息
                console.log("objUrl = "+objUrl);
                if (objUrl) {
                    $("#img").attr("src", objUrl);
                }
            }else{
                return false;
            }
        });
        $('#sub').click(function(){
            var url = $('form').attr('action');
            //获取表单数据
            var form_data = new FormData($("#myform")[0]);
            $.ajax({
                url : url,
                dataType : "json",
                type : "post",
                processData:false,
                contentType:false,
                data : form_data,
                success :function (data) {
                    if(data.status){
                        layer.msg(data.msg,{icon:1,time:1200,end:function () {
                                location.href=data.data;
                            }});
                    }else{
                        layer.msg(data.msg,{icon:5,time:1200});
                    }
                }
            });
        });

        function getObjectURL(file) {
            var url = null;
            if (window.createObjectURL!=undefined) {
                url = window.createObjectURL(file) ;
            } else if (window.URL!=undefined) { // mozilla(firefox)
                url = window.URL.createObjectURL(file);
            } else if (window.webkitURL!=undefined) { // webkit or chrome
                url = window.webkitURL.createObjectURL(file) ;
            }
            return url ;
        }
    });
</script>
{/block}